<template>
  <div v-loading="loading">
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="120px"
      class="dataForm"
    >
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('申请标题')" prop="actTitle">
            <el-input v-model="form.actTitle" :placeholder="$t('申请标题')" show-word-limit :maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('申请人')" prop="applyUserId">
            <UserSelect
              v-model="form.applyUserId"
              :placeholder="this.$t('选择用户')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('申请时间')" prop="applyTime">
            <DatePicker
              v-model="form.applyTime"
              :placeholder="$t('申请时间')"
            />

          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('用印类型(一级)')" prop="usineTypeOne">
            <el-select v-model="form.usineTypeOne" :placeholder="$t('请选择')" filterable clearable @change="usineTypeOneChange(form.usineTypeOne)">
              <el-option
                v-for="dict in oaSealOneTypeDict"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
                collection-summary-report
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col v-if="form.source === '' || form.source === null || form.source === undefined || !(!usineTypeTwoOption.find(obj => obj.dictValue === form.usineTypeTwo))" :span="12">
          <el-form-item :label="$t('用印类型(二级)')" prop="usineTypeTwo">
            <el-select v-model="form.usineTypeTwo" :placeholder="$t('请选择')" filterable clearable>
              <el-option
                v-for="dict in usineTypeTwoOption"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col v-else :span="12">
          <el-form-item>
            <span slot="label">
              {{ $t('用印类型(二级)') }}
              <el-tooltip placement="top">
                <div slot="content">
                  <span v-html="$t('说明: <br>在用印中不存在该选项,该类型来自其他数据沉淀')" />
                </div>
                <i class="el-icon-question" />
              </el-tooltip>
            </span>
            {{ form.usineTypeTwo }}
          </el-form-item>
        </el-col>
        <el-col v-if="form.usineTypeTwo === 'Q'" :span="12">
          <el-form-item :label="$t('其它类型')" prop="otherType">
            <el-input v-model="form.otherType" :placeholder="$t('其它类型')" show-word-limit :maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('文件份数')" prop="fileCount">
            <el-input-number v-model="form.fileCount" :placeholder="$t('文件份数')" show-word-limit :max="10000000" :min="0" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('加盖骑缝章')">
            <el-radio-group v-model="form.sealRidingSeam" size="small">
              <el-radio-button
                v-for="dict in yesNoOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}</el-radio-button>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('关联合同')" prop="contractAssociated">
            <div style="display: flex;">
              <el-select v-model="form.contractAssociated" filterable :placeholder="$t(contractMessage)" :style="{ width: (form.source !== 'dealContract' ? '100%' : '90% !important;') }">
                <el-option
                  v-for="oaContract in selectDropDownContract"
                  :key="oaContract.id"
                  :label="oaContract.name"
                  :value="oaContract.id"
                />
              </el-select>
              <div v-if="form.source !== 'dealContract'">
                <el-button slot="append" icon="el-icon-view" style="width: auto;" @click="viewContractPage(form.contractAssociated)" />
              </div>
            </div>
          </el-form-item>
        </el-col>
        <el-col v-if="!isEmpty(form.usineTypeOne) && (form.usineTypeOne === 'fund' || form.usineTypeOne === 'deal')" :span="12">
          <!-- 项目或基金选择框-->
          <el-form-item :label="form.usineTypeOne === 'fund' ? $t('基金名称') : $t('项目名称')" prop="projectOrFund">
            <el-select v-if="form.usineTypeOne === 'fund'" v-model="form.projectOrFund" filterable clearable :placeholder="$t('请选择')" multiple @change="schange">
              <el-option
                v-for="item in fundDataList"
                :key="item.id"
                :label="item.fundName"
                :value="item.id"
              />
            </el-select>
            <el-select v-if="form.usineTypeOne === 'deal'" v-model="form.projectOrFund" filterable clearable remote :placeholder="$t('请选择')" multiple :remote-method="remoteMethodDeal" @change="schange">
              <el-option
                v-for="item in dealDataList"
                :key="item.id"
                :label="item.dealName"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('合同摘要')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
      </el-row>

      <!--用印明细-->
      <div class="area-header">
        <span class="area-header-title">{{ $t('用印明细') }}</span>
      </div>
      <el-table :data="form.oaSealDetailList" border class="nowrapTable formTable">
        <el-table-column :label="$t('序号')" align="center" width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('用印主体类型')" align="center">
          <template slot="header" slot-scope="{}">
            <i style="color: #ff4949;margin-right: 4px;">*</i>
            <span>{{ $t('用印主体类型') }}</span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'oaSealDetailList.' + scope.$index + '.investMainType'" :rules="oaSealDetailListRules.investMainType">
              <dictSelect
                v-model="scope.row.investMainType"
                :clearable="true"
                dictionary="main_body_type_seal"
                @change="oneInvestType = scope.row.investMainType; scope.row.investMain = undefined; $forceUpdate()"
              />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column :label="$t('用印主体')" align="center">
          <template slot="header" slot-scope="{}">
            <i style="color: #ff4949;margin-right: 4px;">*</i>
            <span>{{ $t('用印主体') }}</span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'oaSealDetailList.' + scope.$index + '.investMain'" :rules="oaSealDetailListRules.investMain">
              <MainBodySelect
                v-model="scope.row.investMain"
                :parameters="scope.row.investMainType"
                @change="changeSealInvest"
              />
            </el-form-item>
          </template>
        </el-table-column>

        <el-table-column :label="$t('印章类型')">
          <template slot="header" slot-scope="{}">
            <i style="color: #ff4949;margin-right: 4px;">*</i>
            <span>{{ $t('印章类型') }}</span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'oaSealDetailList.' + scope.$index + '.sealType'" :rules="oaSealDetailListRules.sealType">
              <el-select
                v-model="scope.row.sealType"
                multiple
                :placeholder="$t('请选择')"
                @change="changeSealType(scope.row.investMain)"
              >
                <el-option
                  v-for="dict in sealTypeDict"
                  :key="dict.dictValue"
                  :label="$t(dict.dictLabel)"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>

        <el-table-column :label="$t('备注')" align="center">
          <template slot-scope="scope">
            <el-form-item :prop="'oaSealDetailList.' + scope.$index + '.remark'" :rules="oaSealDetailListRules.remark">
              <el-input v-model="scope.row.remark" type="textarea" maxlength="2000" show-word-limit :autosize="{ minRows:1,maxRows:10 }" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column v-if="!otherBtnHide" :label="$t('操作')" align="center" width="60px">
          <template slot-scope="scope">
            <el-button v-hasPermi="['oa:seal:remove']" size="small" type="text" icon="el-icon-delete" @click="delHandle(scope.$index, scope.row)" />
          </template>
        </el-table-column>
      </el-table>
      <div v-if="!otherBtnHide" class="tol">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="addPayment">{{ $t('添加明细') }}</el-button>
      </div>

      <!--文件-->
      <FileTable
        :file-title="$t('用印附件信息')"
        :list.sync="form.fileList"
        data-type="oa_seal"
        :business-id="businessId"
        :btn-show="!otherBtnHide"
        :slot-input-box-data="slotInputBoxData"
        @changeSlotInput="changeSlotInput"
        @uploadBeforeTable="uploadBeforeTable"
        @handleChange="handleChange"
      />
      <FileTable
        :file-title="$t('其他附件信息')"
        :list.sync="form.fileListOther"
        data-type="oa_seal_other"
        :business-id="businessId"
        :btn-show="!otherBtnHide"
        @uploadBeforeTable="uploadBeforeTable"
        @handleChange="handleChange"
      />
      <FileTable v-if="form.actStatus === 'W'" :list.sync="form.archivedFileList" file-title="归档附件信息" data-type="oa_seal_archived" :business-id="businessId" :btn-show="!otherBtnHide" />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存，保存并启动流程，取消 三个按钮-->
      <FormBtn ref="formBtn" :bus-data="form" has-permi="oa:seal" :btn-hide="btnHide" :menu-key="menuKey" />
    </div>

    <!-- 查看合同流程 -->
    <el-dialog :visible.sync="contractPageLoading" title="合同详情" :destroy-on-close="true" custom-class="dialogForm" style=" text-align: left;" append-to-body :close-on-click-modal="false" :lock-scroll="false">
      <ProcessInfoForm ref="processInfoForm" />
    </el-dialog>
  </div>
</template>

<script>
import { deleteOaSealDetail, getOaSeal, saveOaSeal } from '@/api/oa/seal/oaSeal'
import { selectSealList } from '@/api/oa/contract/oaContract'
import MainBodySelect from '@/components/MainBodySelect'
import ProcessInfoForm from '@/views/act/process/processInfoForm'
import { formatFileListSlotValue } from '@/api/file/fileTable/fileTableSlot'
import { ruoyiFloat } from '@/utils/ruoyi'
import { findFundFof } from '@/api/fund/fundBase'
import { findDealLimit } from '@/api/base/deal/dealBase'

export default {
        components: {
          MainBodySelect,
          ProcessInfoForm
        },
        data() {
            return {
                // 菜单标识
                menuKey: 'oa_seal',
                // 是否隐藏保存按钮
                btnHide: false,
                // 是否隐藏其它按钮
                otherBtnHide: false,
                loading: false,
                // 表单参数
                form: {
                  archivedFileList: []
                },
                // 表单校验
                title: undefined,
                rules: {
                  applyUserId: [{ required: true, message: this.$t('必填信息'),	trigger: ['blur', 'change'] }],
                  applyTime: [{ required: true, message: this.$t('必填信息'),	trigger: ['blur', 'change'] }],
                  usineTypeOne: [{ required: true, message: this.$t('必填信息'),	trigger: ['blur', 'change'] }],
                  usineTypeTwo: [{ required: true, message: this.$t('必填信息'),	trigger: ['blur', 'change'] }],
                  actTitle: [{ required: true, message: this.$t('必填信息'),	trigger: ['blur', 'change'] }],
                  fileCount: [{ required: true, message: this.$t('必填信息'),	trigger: ['blur', 'change'] }],
                  otherType: [{ required: true, message: this.$t('必填信息'),	trigger: ['blur', 'change'] }]
                },
                // 操作按钮默认不展示
                buttonShow: true,
                // 校验用印明细不能为空
                oaSealDetailListRules: {
                  investMainType: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
                  investMain: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
                  sealType: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }]
                },
                dataType: 'oa_seal',
                uploaderOpen: false,
                // 合同下拉
                selectDropDownContract: [],
                selectDropDownContractTemp: [],
                // 合同下拉,用印类型一级
                oaSealOneTypeDict: [],
                usineTypeOneOption: [],
                // 用印二级类型
                usineTypeTwoOption: [],
                sealTypeDict: undefined,
                contractMessage: this.$t('请选择付款类型后获取合同'),
                contractPageLoading: false,
                selectDropDownContractTempCount: 0,
                yesNoOptions: [],
                slotInputBoxData: [],
                fileSealTypeOption: {},
                fileInvestIdOptions: [],
                fundDataList: [],
                dealDataList: [],
                oneInvestType: [],
                selectLoading: false,
                businessId: undefined
            }
        },
        watch: {
          'form.usineTypeOne': {
            handler(val) {
              if (val) {
                this.getDicts('seal_usine_type_' + val).then(response => {
                  this.usineTypeTwoOption = response.data
                })
              }
            },
            deep: true,
            immediate: true
          },
          'form.projectOrFund': {
            handler(val) {
              if (val) {
                if (this.form.usineTypeOne === 'deal') {
                  this.searchContractSelect(val)
                }
              }
            }
          },
          deep: true,
          immediate: true
        },
        mounted() {
          this.$bus.$emit('async_done')
        },
        created() {
            this.getDicts('seal_type').then(response => {
              this.sealTypeDict = response.data
            })
            this.getDicts('seal_usine_type').then(response => {
              this.oaSealOneTypeDict = response.data
            })
            this.getDicts('sys_yes_no').then(response => {
              this.yesNoOptions = response.data
            })
            this.findListData()
        },
        methods: {
            // 初始化数据
            init(data) {
                this.slotInputBoxData = this.initFileFieldDefault()
                this.selectDropDownContractTempCount = 0
                this.contractMessage = this.$t('请选择付款类型后获取合同')
                if (data != null && data !== '' && data.id !== undefined) {
                    this.loading = true
                    getOaSeal(data.id).then(response => {
                        this.form = response.data
                        this.initFileFieldValue()
                        this.remoteMethodDeal()
                        this.loading = false
                    })
                } else {
                    this.loading = false
                    this.remoteMethodDeal()
                    this.reset()
                }
            },
            // 给动态组件初始化字段
            initFileFieldValue() {
              this.slotInputBoxData = []
              this.fileInvestIdOptions = []
              this.initSlotInvestTypeDict()
              this.slotInputBoxData = this.initFileFieldDefault()
              // 加载附件绑定的
              if (this.form.fileList) {
                // 调整
                console.log('tiaozheng')
                this.form.fileList.forEach((item, index) => {
                  if (this.isEmpty(item.slotData)) {
                    item.slotData = this.initFileFieldDefault()
                  } else {
                    // 回显
                    var tempSlotData = this.initFileFieldDefault()
                    item.slotData && item.slotData.forEach((slot) => {
                      // 回显附主体章
                      tempSlotData && tempSlotData.forEach(data => {
                        if (data.model === slot.model && item.id === slot.dataId) {
                          data.dataId = slot.dataId
                          if (slot.model === 'investSealType') {
                            data.value = this.getSelectValueArr(slot.value)
                          }
                          // 回显印章数量
                          if (slot.model === 'copies') {
                            if (!this.isEmpty(slot.value)) {
                              data.value = parseInt(slot.value)
                            }
                          }
                        }
                      })
                    })
                    this.$set(this.form.fileList[index], 'slotData', tempSlotData)
                  }
                })
              }
              this.$forceUpdate()
            },
            initFileFieldDefault() {
              return [
                { type: 'select', label: this.$t('主体及印章'), model: 'investSealType', placeholder: this.$t('请选择'), minWidth: 160, multiple: true, selectOptions: this.fileInvestIdOptions, required: true, value: [] },
                { type: 'input', label: this.$t('份数'), model: 'copies', placeholder: this.$t('份数'), minWidth: 80, required: true, value: undefined }
              ]
            },
            /**
             * 用印主体变化
             */
            changeSealInvest(e, name) {
              var tempArr = []
              var flag = true
              this.form.oaSealDetailList && this.form.oaSealDetailList.some((item, index) => {
                if (name !== undefined && e === item.investMain) {
                  item.investMainName = name
                }
                if (!tempArr.includes(item.investMain) || this.isEmpty(item.investMain)) {
                  tempArr.push(item.investMain)
                } else {
                  this.$nextTick(() => {
                    this.$set(this.form.oaSealDetailList[index], 'investMain', '')
                  })
                  flag = false
                  return true
                }
              })
              this.$forceUpdate()
              if (flag) {
                this.initFileFieldValue()
              } else {
                this.msgWarning(this.$t('用印主体不能重复'))
              }
            },
            // 印章类型变化
            changeSealType(investMain) {
              console.log(investMain)
              this.initFileFieldValue()
            },
            // 为主表累计分数
            changeSlotInput(data) {
              // 是数据累计. 不是数据清空输入内容
              data.e = Number(data.e)
              if (typeof data.e === 'number' && !isNaN(data.e)) {
                var temp = 0
                this.form.fileList && this.form.fileList.forEach((item, index) => {
                  item.slotData && item.slotData.forEach(item2 => {
                    if (item2.model === 'copies') {
                      if (index === data.index && data.e !== '' && !this.isEmpty(data.e)) {
                        temp += ruoyiFloat().formatNum(data.e) === Infinity ? 0 : ruoyiFloat().formatNum(data.e)
                      } else {
                        temp += ruoyiFloat().formatNum(item2.value) === Infinity ? 0 : ruoyiFloat().formatNum(item2.value)
                      }
                    }
                  })
                })
                this.$set(this.form, 'fileCount', temp)
              } else {
                this.form.fileList && this.form.fileList.forEach((item, index) => {
                  item.slotData && item.slotData.forEach((item2, index2) => {
                    if (item2.model === 'copies') {
                      if (index === data.index && data.e !== '' && !this.isEmpty(data.e)) {
                        // 清空输入的内容
                        this.form.fileList[index].slotData[index2].value = ''
                      }
                    }
                  })
                })
              }
            },
            // 翻译字典
            translationDictSealType(val) {
              var find = this.sealTypeDict.find(obj => obj.dictValue === val)
              if (find) {
                return find.dictLabel
              }
              return ''
            },
            schange(val, name) {
              console.log(name, val)
              this.form.contractAssociated = undefined
            },
            // 表单重置
            reset() {
                this.form = {
                id: undefined,
                applyUserId: this.$store.state.user.userId,
                applyTime: new Date(),
                usineTypeOne: undefined,
                usineTypeTwo: undefined,
                otherType: undefined,
                fileCount: undefined,
                sealRidingSeam: undefined,
                contractAssociated: undefined,
                projectOrFund: undefined,
                sealType: undefined,
                source: undefined,
                remark: undefined,
                createBy: undefined,
                createTime: undefined,
                updateBy: undefined,
                updateTime: undefined,
                fileList: [],
                fileListOther: [],
                delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
              if (this.$parent.$parent.formOpen !== undefined) {
                this.$parent.$parent.formOpen = false
              }
              if (this.$parent.$parent.reset !== undefined) {
                this.$parent.$parent.reset()
              }
            },
            // 关闭form页面
            closeForm() {
              // 关闭form页面遮罩层
              this.loading = false
              // 关闭form页面
              if (this.$parent.$parent.formOpen !== undefined) {
                this.$parent.$parent.formOpen = false
              }
              // 刷新list页面
              if (this.$parent.$parent.getList !== undefined) {
                this.$parent.$parent.getList()
              }
            },
            /** 提交按钮 */
            submitForm: function(type) {
              // if (!this.form.fileList || this.form.fileList.length === 0) {
              //   this.$message.error('请上传用印文件')
              //   return false
              // }
              return new Promise((resolve, reject) => {
                var temp = this.form.oaSealDetailList
                if (temp === null || temp === undefined || temp === '' || temp <= 0) {
                  this.msgError(this.$t('至少添加一条用印明细'))
                } else {
                   this.$refs['form'].validate(valid => {
                       // 验证数据
                       if (valid) {
                         // 弹出遮罩层
                         this.loading = true
                         console.log(this.form)
                         // 保存数据
                         // 保存前将slot转为string
                         formatFileListSlotValue(this.form.fileList)
                         saveOaSeal(this.form).then(response => {
                            if (response.code === 200) {
                              // 点击的按钮是保存并启动流程
                              if (type === 'process') {
                                // 设置数据id方式启动流程后取消并再次启动会创建多条记录
                                // this.form = response.data
                                getOaSeal(response.data.id).then(res => {
                                  this.form = res.data
                                  this.initFileFieldValue()
                                  // 启动流程
                                  this.startProcess(response.data.id)
                                })
                              } else {
                                this.msgSuccess(this.$t('保存成功'))
                                // 关闭form页面
                                this.closeForm()
                              }
                              resolve()
                            } else {
                              this.msgError(response.msg)
                              this.loading = false
                              reject()
                            }
                         }).catch(() => {
                           this.loading = false
                         })
                       } else {
                         this.locationError(document)
                         reject()
                       }
                   })
                }
              })
            },
            // 启动流程
            startProcess: function(dataId) {
              this.loading = false
              // 启动流程时候传入的参数
              const processData = {}
              // 待办标题
              processData.title = this.form.actTitle
              // 业务表名
              processData.dataTable = 'oa_seal'
              // 业务ID
              processData.dataId = dataId
              // 业务表单地址
              processData.formPath = '@/views/oa/seal/oaSealForm'

              // 业务表单打印地址
              processData.viewPath = '@/views/oa/seal/oaSealView'

              // 菜单标识(根据菜单标识判断的走哪个流程)
              processData.menuKey = this.menuKey
              this.startProcessByMenu(processData, () => {
                this.form.actStatus = 'D'
                this.msgSuccess(this.$t('数据保存成功,流程启动成功'))
                this.closeForm()
              })
            },
            searchContractSelect(dealId) {
              this.selectDropDownContract = []
              this.selectDropDownContractTemp = []
              if (typeof dealId === 'object') {
                dealId && dealId.forEach(item => {
                  selectSealList({ dealId: item }).then(response => {
                    response.data && response.data.forEach(d => {
                      this.selectDropDownContract.push(d)
                    })
                    if (this.selectDropDownContractTempCount <= 0) {
                      this.selectDropDownContractTemp = response.data
                      this.selectDropDownContractTempCount++
                    }
                  })
                })
              } else {
                selectSealList({ dealId: dealId }).then(response => {
                  this.selectDropDownContract = response.data
                  if (this.selectDropDownContractTempCount <= 0) {
                    this.selectDropDownContractTemp = response.data
                    this.selectDropDownContractTempCount++
                  }
                })
              }
            },
            // 用印明细
            addPayment() {
              const row = {
                id: undefined,
                investMainType: '',
                investMain: '',
                sealType: '',
                remark: ''
              }
              if (!(this.form.oaSealDetailList instanceof Array)) {
                this.$set(this.form, 'oaSealDetailList', [])
              }
              this.$nextTick(() => {
                this.form.oaSealDetailList.push(row)
              })
            },
            // 删除用印明细
            delHandle(index, row) {
              // eslint-disable-next-line no-undef
              const id = row.id
              if (id !== undefined && id !== '' && id != null) {
                this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
                  confirmButtonText: this.$t('确定'),
                  cancelButtonText: this.$t('取消'),
                  type: 'warning'
                })
                  .then(function() {
                    return deleteOaSealDetail(id)
                  }).then(() => {
                  this.form.oaSealDetailList.splice(index, 1)
                  this.changeSealInvest()
                  return this.msgSuccess(this.$t('删除成功'))
                })
                  .catch(function() {})
              } else {
                this.form.oaSealDetailList.splice(index, 1)
                this.changeSealInvest()
              }
            },
            // 添加附件
            uploader() {
              this.uploaderOpen = true
              this.title = '上传附件'
            },
            // 获取附件列表
            getData(fileList) {
              this.form.fileList = fileList
            },
            // 删除附件
            delAdjunct(index) {
              this.form.fileList.splice(index, 1)
            },
            //
            usineTypeOneChange(usineTypeOne) {
              this.form.projectOrFund = undefined
              this.form.usineTypeTwo = undefined
              this.form.contractAssociated = undefined
              // 基金或项目时 清空OA合同. 日常用印时恢复OA合同
              this.oaSealOneTypeDict.some(item => {
                if (item.dictValue === usineTypeOne) {
                  this.form.businessType = usineTypeOne
                  if (usineTypeOne === 'deal') {
                    this.selectDropDownContract = []
                    this.contractMessage = this.$t('请先选择项目,加载相应合同')
                  } else {
                    this.contractMessage = this.$t('请选择合同')
                    this.selectDropDownContract = this.selectDropDownContractTemp
                  }
                  if (usineTypeOne === 'deal' || usineTypeOne === 'fund') {
                    this.rules.projectOrFund = [{ required: true, message: this.$t('必填信息'), trigger: 'change' }]
                  } else {
                    this.rules.projectOrFund = []
                  }
                }
              })
            },
            viewContractPage(id) {
              var proArr = this.selectDropDownContract
              if (proArr !== null && proArr !== undefined && proArr !== '') {
                proArr.forEach(item => {
                  if (id === item.id) {
                    if (item.actId === undefined) {
                      id = item.rows.actId
                    } else {
                      id = item.actId
                    }
                  }
                })
              }
              if (id !== null && id !== '' && id !== undefined) {
                console.log(id)
                this.contractPageLoading = true
                this.$nextTick(() => {
                  var proData = {}
                  proData.actId = id
                  this.$refs.processInfoForm.init(proData)
                })
              } else {
                this.msgError(this.$t('请先选择一个合同!'))
              }
            },
            isEmpty(val) {
              return val === undefined || val === null || val.length <= 0 || val === ''
            },

          // 初始化动态字段下拉
          initSlotInvestTypeDict() {
            this.form.oaSealDetailList && this.form.oaSealDetailList.forEach((item) => {
              item.sealType && item.sealType.forEach(type => {
                var dictLabel = item.investMainName
                // 如果dictLabel最后一个字符是中文)则去不加空格
                if (dictLabel && dictLabel.charAt(dictLabel.length - 1) !== '）') {
                  dictLabel = dictLabel + ' '
                }
                this.fileInvestIdOptions.push({
                  dictValue: item.investMain + '_' + type,
                  dictLabel: dictLabel + '一 ' + this.translationDictSealType(type)
                })
              })
            })
          },
          // 修改主题时, 判断选中的主体中是否依然存在, 不存在就清空
          getSelectValueArr(value) {
            var result = []
            var arr = []
            try {
              if (typeof value === 'string') {
                arr = JSON.parse(value)
              } else {
                arr = value
              }
              arr && arr.forEach(item => {
                this.fileInvestIdOptions.forEach(sub => {
                  if (item === sub.dictValue) {
                    result.push(item)
                  }
                })
              })
              return result
            } catch (e) {
              console.log(e)
            }
            return result
          },
          uploadBeforeTable(callback) {
            this.businessId = undefined
            if (this.isEmpty(this.form.projectOrFund)) {
              this.businessId = undefined
              callback()
            } else {
              if (this.form.projectOrFund.length === 1) {
                this.businessId = this.form.projectOrFund[0]
                callback()
              } else {
                var that = this
                const h = this.$createElement
                var map = []
                this.form.projectOrFund.forEach(item => {
                  this.dealDataList.forEach(dict => {
                    if (dict.id === item) {
                      map.push({ id: dict.id, name: dict.dealName })
                    }
                  })
                  this.fundDataList.forEach(dict => {
                    if (dict.id === item) {
                      map.push({ id: dict.id, name: dict.fundName })
                    }
                  })
                })
                this.$msgbox({
                  title: this.$t('请选择') + this.form.usineTypeOne === 'fund' ? this.$t('基金') : this.$t('项目'),
                  message: h('el-select',
                    { props: { value: that.businessId, filterable: true },
                      ref: 'selectView',
                      style: { width: '100%' },
                      on: {
                        change: e => {
                          console.log('12change', e)
                          that.businessId = e
                          that.$refs.selectView.value = e
                        }
                      }
                    },
                    [
                      map.map(it => {
                        return h('el-option', {
                          props: { label: it.name, key: it.id, value: it.id }
                        })
                      })
                    ]
                  ),
                  showCancelButton: true,
                  closeOnClickModal: false,
                  confirmButtonText: this.$t('确定'),
                  cancelButtonText: this.$t('取消'),
                  beforeClose: (action, instance, done) => {
                    if (action === 'confirm') {
                      if (that.businessId) {
                        done()
                      } else {
                        this.$message.warning(this.$t('请先选择'))
                      }
                    } else {
                      done()
                    }
                  }
                }).then(() => {
                  console.log(that.businessId)
                  callback()
                }).catch(() => {
                })
              }
            }
          },
          handleChange() {
            this.form.fileList && this.form.fileList.forEach(item => {
              item.businessId = this.businessId
            })
            this.form.fileListOther && this.form.fileListOther.forEach(item => {
              item.businessId = this.businessId
            })
          },
          remoteMethodDeal(query) {
            this.selectLoading = true
            const queryDeal = {
              pageSize: 30,
              pageNum: 1,
              dealIdList: (this.form.projectOrFund !== Array) ? (this.isEmpty(this.form.projectOrFund) ? [] : this.form.projectOrFund) : (this.form.projectOrFund.filter(i => i && i.trim())),
              dealName: query,
              scopeAuthority: true
            }
            findDealLimit(queryDeal).then(response => {
              this.dealDataList = (response.rows === null ? [] : response.rows)
              this.selectLoading = false
            }).catch(() => {
              this.selectLoading = false
            })
          },
          findListData() {
            findFundFof({ scope: this.scopeAuthority }).then(response => {
              this.fundDataList = response.data
            })
          }
        }
    }
</script>
